package com.example.paopao.consumer.memer.dao.persist.repository.impl;

import com.example.paopao.consumer.memer.dao.persist.mapper.ReleaseDetailMapper;
import com.example.paopao.consumer.memer.dao.persist.repository.IReleaseDetailRepository;
import com.example.paopao.consumer.memer.pojo.entity.Release;
import com.example.paopao.consumer.memer.pojo.entity.TransDistrict;
import com.example.paopao.consumer.memer.pojo.temp.ReleaseWorkTemp;
import com.example.paopao.consumer.memer.pojo.vo.TranDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
@Slf4j
public class ReleaseDetailRepositoryImpl implements IReleaseDetailRepository {

    @Autowired
    private ReleaseDetailMapper detailMapper;

    @Override
    public List<TranDetailVO> listReleaseDetail() {
        return detailMapper.listReleaseDetail();
    }

    @Override
    public int addNewTrans(ReleaseWorkTemp releaseWorkTemp) {
        Release release=new Release();
        release.setTransactionId(Long.valueOf(releaseWorkTemp.getObjective().get(0).toString()));
        release.setDetailId(Long.valueOf(releaseWorkTemp.getObjective().get(1).toString()));
        release.setUserId(releaseWorkTemp.getUserId());
        release.setInDetail(releaseWorkTemp.getDetail());
        release.setPhone(releaseWorkTemp.getPhone());
        release.setContact(releaseWorkTemp.getContacts());
        release.setCreateTime(LocalDateTime.now());
        release.setSort(0L);
        release.setIsDisplay(true);

        long  newTrans = detailMapper.addNewTrans(release);

        TransDistrict transDistrict=new TransDistrict();
        transDistrict.setUrbanId(releaseWorkTemp.getDistrict().get(0));
        transDistrict.setCityId(releaseWorkTemp.getDistrict().get(1));
        transDistrict.setReleaseId(release.getId());

        detailMapper.addNewTransDistrict(transDistrict);

        return 1;
    }
}
